capture program drop sumstat_panel
program define sumstat_panel
* `1' Excel file for output
* `2' Sheet of the excel file
* `3' Variable of interest
	quietly sum `3', d
	local count=r(N)
	local mean=r(mean)
	local median=r(p50)
	local p10=r(p10)
	local p25=r(p25)	
	local p75=r(p75)
	local p90=r(p90)
	putexcel set `1' , sheet("`2'") modify
	#delimit ; 
	putexcel A3=("All") B1=("`3'") 
	 B2=("Count") C2=("Mean") D2=("Median") E2=("P10") F2=("P25") G2=("P75")  H2=("P90")
	 B3=(`count') C3=(`mean') D3=(`median') E3=(`p10') F3=(`p25') G3=(`p75')  H3=(`p90') 
	; 
	#delimit cr 
	local j=1
	foreach c in $countrysample{
		local k=3+`j'
		use temp, clear
		keep if iso2=="`c'"
		quietly sum `3', d
		local count=r(N)
		local mean=r(mean)
		local median=r(p50)
		local p10=r(p10)
		local p25=r(p25)	
		local p75=r(p75)
		local p90=r(p90)
		putexcel set `1' , sheet("`2'") modify
		#delimit ; 
		putexcel A`k'=("`c'") 
		 B`k'=(`count') C`k'=(`mean') D`k'=(`median') E`k'=(`p10') F`k'=(`p25') G`k'=(`p75')  H`k'=(`p90') 
		; 
		#delimit cr 
		local j=`j'+1
	}
end
